import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 路由映射数组
const routes = [{
  path: '/login',
  name: 'login',
  component: () =>
    import('@/views/login/index.vue')
},
{
  path: '/',
  name: 'layout',
  component: () =>
    import('@/views/layout/index.vue'),
  redirect: '/home',
  children: [{
    path: 'home',
    name: 'home',
    component: () =>
      import('@/views/home/index.vue')
  },
  {
    path: 'wenda',
    name: 'wenda',
    component: () =>
      import('@/views/wenda/index.vue')
  },
  {
    path: 'video',
    name: 'video',
    component: () =>
      import('@/views/video/index.vue')
  },
  {
    path: 'my',
    name: 'my',
    component: () =>
      import('@/views/my/index.vue')
  }
  ]
},
{
  path: '/search',
  name: 'search',
  component: () =>
    import('@/views/search/index.vue')
},
{
  path: '/article/:articleId',
  name: 'article',
  component: () =>
    import('@/views/article/index.vue'),
  props: true
},
{
  path: '/user/profile',
  name: 'user-profile',
  component: () =>
    import('@/views/user-profile/index.vue'),
  meta: { needLogin: true } // 增加一个needLogin用于判断页码是否需要登录
}
]
// 实例化路由对象
const router = new VueRouter({
  routes
})

export default router
